import { request } from "./index"

//*----------- 手机号 密码登录 --------------------------

interface CouldUserInfoModel {
  code: number //登录请求状态码
  profile: { userId: number }
}

export const reqPhoneLogin = (phone: string, password: string) =>
  request<CouldUserInfoModel>(
    {
      url: "/login/cellphone",
      method: "POST",
      data: { phone, password },
      params: { t: Date.now() },
    },
    true
  )

export const reqLogout = () =>
  request<CouldUserInfoModel>({
    url: "/logout",
    method: "GET",
  })

//*---------------根据uid获取用户详细信息，登录获取的信息有缺漏的字段，不够详细----------------------

export interface ProfileModel {
  backgroundUrl: string //头上的背景图
  userId: number
  gender: number //性别 1男 2女
  nickname: string //昵称
  birthday: number //生日当天零点时间戳
  offsetAge?: string //!根据时间戳转换成 90后/95后/00后
  astro?: string //!根据时间戳转换成 星座
  avatarUrl: string //头像链接
  followeds: number //粉丝数
  follows: number //关注数
  province: number //省份代码
  provinceName?: string //!处理后得出的省份名
  city: number //城市代码
  cityName: string //!处理后得出的城市名
  createTime: number //账户创建时间
  createYear?: number //!处理后得出的村龄
}

interface reqCouldUserProfileResModel {
  level: number //等级
  profile: ProfileModel
  // code: number
}

export const reqCouldUserProfile = (uid: number) =>
  request<reqCouldUserProfileResModel>({
    url: "/user/detail",
    method: "GET",
    data: { uid },
  })

//* -------------获取用户的歌单列表，包含自己创建歌单与收藏的歌单---------------------

export interface CreatorModel {
  userId: number //用来判断是否和自己的userId一致，一致的话就是自己创建的歌单
  avatarUrl: string //头像
  nickname: string //昵称
}

export interface UserPlayListModel {
  //true为收藏的歌单，false为自己创建的歌单，包含我喜欢的歌单，需要过滤展示
  // subscribed: boolean
  creator: CreatorModel
  subscribedCount: number //被收藏的数量
  trackCount: number //歌单曲目数量
  coverImgUrl: string //歌单封面
  playCount: number //播放次数
  name: string //歌单名
  id: number //歌单id
}

export const reqUserPlaylist = (uid: number) =>
  request<{ playlist: UserPlayListModel[] }>({
    url: "/user/playlist",
    method: "GET",
    params: { uid },
  })

//* ------------------获取播放记录--------------------------

export interface UserRecord {
  playCount: number
  //因为ScrollXPlaylist组件需要指定特定的字段，
  localPlayCount: string //格式化后加的字段
  name: string //格式化加的字段，把下面对象里的内容提取
  picUrl: string //格式化加的字段
  id: number //格式化加的字段
  song: {
    name: string
    id: number
    al: {
      id: number
      picUrl: string
      name: string
    }
    ar: {
      id: number
      name: string
    }[]
  }
}

export const reqUserRecord = (uid: number) =>
  request<{ weekData: UserRecord[] }>({
    url: "/user/record",
    method: "GET",
    //type为1表示获取最近1周的数据
    params: { uid, type: 1 },
  })
